﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;

namespace Chenxin.Lib.House.BLL
{
    /// <summary>
    /// 业务逻辑类Customer_ViewHouseInfo 的摘要说明。
    /// </summary>
    public class Customer_ViewHouseInfo
    {

        public Customer_ViewHouseInfo()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public static bool Exists(Guid RecordId)
        {
            return Chenxin.Lib.House.DAL.Customer_ViewHouseInfo.Exists(RecordId);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.House.Entity.Customer_ViewHouseInfo model)
        {
            Chenxin.Lib.House.DAL.Customer_ViewHouseInfo.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.House.Entity.Customer_ViewHouseInfo model)
        {
            Chenxin.Lib.House.DAL.Customer_ViewHouseInfo.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid RecordId)
        {

            Chenxin.Lib.House.DAL.Customer_ViewHouseInfo.Delete(RecordId);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.House.Entity.Customer_ViewHouseInfo GetModel(Guid RecordId)
        {

            return Chenxin.Lib.House.DAL.Customer_ViewHouseInfo.GetModel(RecordId);
        }


        public static DataSet GetModelId(string CustomerId)
        {
            string strWhere = string.Format("CustomerId='{0}'", CustomerId);
            DataSet dsModel = GetList(strWhere);
            return dsModel;
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            return Chenxin.Lib.House.DAL.Customer_ViewHouseInfo.GetList(strWhere);
        }

       
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        //*******************************************
        //功能概要       ：根据当前节点类型获取带看
        //参数説明       ：dicParams-参数列表
        //返回值説明     ：带看列表
        //功能詳細       ：根据当前节点类型获取带看
        //作成者         ：何基锋
        //作成日         ：2010-08-12
        //*******************************************
        public static DataSet GetViewHouseListByParams(Dictionary<string, string> dicParams)
        {
            DataSet ds = null;

            int PageIndex = 1;
            int PageSize = 10;

            string OrderField = " Customer_ViewHouseInfo.ViewTime DESC";
            string TableName = "Customer_ViewHouseInfo";
            StringBuilder strWhere = new StringBuilder();

            string FieldList = "CustomerName, Reportor, ReportDepart, Operator, OprDepart, ViewTime";

            string TableFieldList = "CustomerName, Reportor, ReportDepart, Operator, OprDepart, ViewTime";

            if (dicParams.ContainsKey("sort"))
            {
                OrderField = dicParams["sort"];
            }

            strWhere.Append(" 1=1 ");

            if (dicParams.ContainsKey("PageIndex"))
            {
                PageIndex = Convert.ToInt32(dicParams["PageIndex"]);
            }
            if (dicParams.ContainsKey("PageSize"))
            {
                PageSize = Convert.ToInt32(dicParams["PageSize"]);
            }

            if (dicParams.ContainsKey("StartDate"))
            {
                strWhere.AppendFormat(" AND ViewTime >= '{0}'", dicParams["StartDate"]);
            }

            if (dicParams.ContainsKey("EndDate"))
            {
                strWhere.AppendFormat(" AND ViewTime <= '{0}'", dicParams["EndDate"]);
            }

            if (dicParams.ContainsKey("ParentType"))
            {
                string ParentType = dicParams["ParentType"];
                switch (ParentType)
                {
                    case "0":
                        strWhere.AppendFormat("AND CityId='{0}'", dicParams["ParentId"]);
                        break;
                    case "10":
                        strWhere.AppendFormat("AND CompanyId='{0}'", dicParams["ParentId"]);
                        break;
                    case "20":
                        strWhere.Append("AND EXISTS(");
                        strWhere.Append("       SELECT 1");
                        strWhere.Append("       FROM Chenxin_Main.dbo.Hr_Struct_DepartTreeRelation R");
                        strWhere.Append("       WHERE Customer_ViewHouseInfo.DepartId = R.ChildId");
                        strWhere.AppendFormat(" AND ParentId='{0}'", dicParams["ParentId"]);
                        strWhere.Append("   )");
                        break;
                    case "25":
                    case "30":
                        strWhere.AppendFormat("AND DepartId='{0}'", dicParams["ParentId"]);
                        break;
                    case "40":
                        strWhere.AppendFormat("AND ReportorId='{0}'", dicParams["ParentId"]);
                        break;
                    default:
                        break;
                }
            }

            ds = Chenxin.Lib.House.DAL.Customer_ViewHouseInfo.GetList(PageIndex, PageSize, OrderField, TableName, strWhere.ToString(), FieldList, TableFieldList, true);
            return ds;
        }

        #endregion  成员方法
    }
}

